﻿using Shared.DJDBDK;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ModemSystemNew
{
    public partial class FormNew : Form
    {
        public FormNew()
        {
            InitializeComponent();
        }

        private void FormNew_Load(object sender, EventArgs e)
        {
            //byte[] a = { 0xFC,2,3,4,0xFF};
            //byte b=Shared.Method.PortBaseClass.CalculationChecksum(a);
            //MessageBox.Show(b.ToString());

            string version = Application.ProductVersion.ToString();

            this.Text = string.Format("友创达统一测试软件 V{0}", version);

            //初始化语音卡
            bool initVoice = VoiceBaseClass.InitVoiceCard(out string msg);

            if (initVoice == false)
            {
                MessageBox.Show("初始化语音卡失败");
                //Close();
            }

            if (VoiceBaseClass.TotalLine != 8) { MessageBox.Show("初始化语音接口数目不为8，请检查"); }

            FlowLayoutPanel panel = null;

            for (int i = 1; i <= 8; i++)
            {
                //获取需要调用的panel
                switch (i)
                {
                    case 1:
                        panel = this.flowLayoutPanel1;
                        break;
                    case 2:
                        panel = this.flowLayoutPanel2;
                        break;
                    case 3:
                        panel = this.flowLayoutPanel3;
                        break;
                    case 4:
                        panel = this.flowLayoutPanel4;
                        break;
                    case 5:
                        panel = this.flowLayoutPanel5;
                        break;
                    case 6:
                        panel = this.flowLayoutPanel6;
                        break;
                    case 7:
                        panel = this.flowLayoutPanel7;
                        break;
                    case 8:
                        panel = this.flowLayoutPanel8;
                        break;
                    default:
                        break;
                }

                //初始化产品
                panel.Controls.Clear();

                WriteUint unit = new WriteUint(i);
                panel.Controls.Add(unit);
                unit.Show();
            }
        }

        private void FormNew_FormClosed(object sender, FormClosedEventArgs e)
        {
            //close all serial posts
            Common.ReleaseSerial();

            VoiceBaseClass.ExitVoiceCard();
        }
    }
}
